package com.sky.mapper;

import com.sky.entity.SetmealDish;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealDishMapper {

    /**
     * 从菜品和套餐关系表查询菜品和套餐关系集合
     * @param dishId
     * @return
     */
    @Select("select id, setmeal_id, dish_id, name, price, copies from setmeal_dish " +
            "where dish_id = #{dishId}")
    List<SetmealDish> get(long dishId);

    /**
     * 添加一条套餐和菜品关系信息到套餐和菜品关系表
     * @param setmealDish
     */
    @Insert("insert setmeal_dish(setmeal_id, dish_id, name, price, copies) " +
            "values (#{setmealId}, #{dishId}, #{name}, #{price}, #{copies})")
    void save(SetmealDish setmealDish);

    /**
     * 根据套餐id从套餐和菜品关系表查询套餐和菜品关系信息
     * @param id
     * @return
     */
    @Select("select id, setmeal_id, dish_id, name, price, copies from setmeal_dish " +
            "where setmeal_id = #{setmealId}")
    List<SetmealDish> getBySetmealId(Long id);

    /**
     * 根据套餐id从套餐和菜品关系表删除套餐和菜品关系信息
     * @param id
     */
    @Delete("delete from setmeal_dish where setmeal_id = #{setmealId}")
    void delBySetmealId(Long id);

    /**
     * 根据菜品id从套餐和菜品关系表修改套餐和菜品关系信息
     * @param build
     */
    void updateByDishId(SetmealDish build);
}
